package com.insurance.web;

import java.util.List;

import javax.annotation.Resource;
import com.insurance.bean.Admin;
import com.insurance.service.AdminService;


public class AdminAction {
	@Resource AdminService adminService;
	private String message;
	private List<Admin> admins;
	private Admin admin;
	private Integer id;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Admin getAdmin() {
		return admin;
	}
	public void setAdmin(Admin admin) {
		this.admin = admin;
	}
	/**
	 * 显示管理员
	 */
	public String list(){
		this.admins = adminService.getAdmins();
		return "list";
	}
	/**
	 * 管理员增加界面
	 */
	public String addUI(){
		return "add";
	}
	/**
	 * 新增管理员
	 */
	public String add(){
		this.adminService.save(this.admin);
		this.message="添加成功！";
		return "message";
	}
	
	/**
	 * 
	 * 修改界面
	 */
	public String modifyUI(){
		this.admin = this.adminService.getAdmin(this.id);
		return "modify";
	}
	/**
	 * 
	 * 修改管理员
	 */
	public String modify(){
		this.adminService.update(this.admin);
		this.message="修改成功！";
		return "message";
	}
	/**
	 * 	
	 * 删除管理员
	 */
	public String del(){			
			this.adminService.delete(this.id);
			this.message="删除成功！";
			return "message";
	}
	public List<Admin> getAdmins() {
		return admins;
	}

	public void setAdmins(List<Admin> admins) {
		this.admins = admins;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public String verifyAdmin(){
		if((adminService.verifyAdmin(admin)) == null)
		return "fail";
		else 
			return "success";
	}
	
/*	public String verifyAdmin() {
		if ((admin = adminService.verifyAdmin(admin)) == null)
			return "fail";
		ActionContext.getContext().getSession().put("admin", admin);
//		List clientList = personnelService.getAllPersonnels(Personnel.CLIENT);
//		List productList = personnelService.getAllPersonnels(Personnel.PRODUCT);
//		List saleList = personnelService.getAllPersonnels(Personnel.SALE);
//		ServletActionContext.getRequest().setAttribute("clientList", clientList); 
//		ServletActionContext.getRequest().setAttribute("productList", productList); 
//		ServletActionContext.getRequest().setAttribute("saleList", saleList);
		return "success";
	}
*/
}
